﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FlashCards.Tests.NeuralNetworkTest.Simulations
{
    public class NeuralNetworkUtils
    {
        public static double CalculateFlashcardsMark(Model.NeuralNetworkResults results)
        {
            var sum = 0.0m;
            if (IsUnknownTheGreatest(results))
            {
                sum = 0.1m * 1m * results.Unknown + 0.15m * results.Poor + 0.3m * results.Average + 0.45m * results.Good;
            }
            else if (IsPoorTheGreatest(results))
            {
                sum = -0.15m * results.Unknown + 0.2m * 1m * results.Poor + 0.15m * results.Average + 0.3m * results.Good;
            }
            else if (IsAverageTheGreatest(results))
            {
                sum = -0.3m * results.Unknown + -0.15m * results.Poor + 0.3m * 1m * results.Average + 0.15m * results.Good;
            }
            else if (IsGoodTheGreatest(results))
            {
                sum = -0.45m * results.Unknown + -0.3m * results.Poor + -0.15m * results.Average + 0.5m * 1m * results.Good;
            }
            return (double)sum * 2;
        }

        #region HELPERS

        private static bool IsUnknownTheGreatest(Model.NeuralNetworkResults result)
        {
            if (result.Unknown > result.Poor && result.Unknown > result.Average && result.Unknown > result.Good)
                return true;
            return false;
        }

        private static bool IsPoorTheGreatest(Model.NeuralNetworkResults result)
        {
            if (result.Poor > result.Unknown && result.Poor > result.Average && result.Poor > result.Good)
                return true;
            return false;
        }

        private static bool IsAverageTheGreatest(Model.NeuralNetworkResults result)
        {
            if (result.Average > result.Unknown && result.Average > result.Poor && result.Average > result.Good)
            {
                return true;
            }
            return false;
        }

        private static bool IsGoodTheGreatest(Model.NeuralNetworkResults result)
        {
            if (result.Good > result.Unknown && result.Good > result.Poor && result.Good > result.Average)
                return true;
            return false;
        }

        #endregion
    }
}
